﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Application.Admin.MobileClient
{
    public class MobileClientStartLogService : IMobileClientStartLogService
    {
        Domain.Uow.IRepository<Domain.Entity.MobileClientStartLog> clientLogRepository;

        public MobileClientStartLogService(Domain.Uow.IRepository<Domain.Entity.MobileClientStartLog> sight)
        {
            if (sight == null)
            {
                throw new ArgumentNullException("clientLogRepository is null");
            }
            clientLogRepository = sight;
        }

        public Domain.Entity.MobileClientStartLog Add(Domain.Entity.MobileClientStartLog add, Domain.Entity.User operUser)
        {
            if (add == null) return add;
            clientLogRepository.Add(add);
            clientLogRepository.Uow.Commit();
            return add;
        }

        public bool Delete(Domain.Entity.MobileClientStartLog delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                delete.State = false;
                clientLogRepository.Modify(delete);
                clientLogRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(Domain.Entity.MobileClientStartLog delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                clientLogRepository.Delete(delete);
                clientLogRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Delete(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = clientLogRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                item.State = false;
                clientLogRepository.Modify(item);
            }
            try
            {
                clientLogRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = clientLogRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                clientLogRepository.Delete(item);
            }
            try
            {
                clientLogRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Modify(Domain.Entity.MobileClientStartLog modify, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                clientLogRepository.Modify(modify);
                clientLogRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public Domain.Entity.MobileClientStartLog Get(int id)
        {
            var data = clientLogRepository.Get(id);
            return data;
        }

        public IQueryable<Domain.Entity.MobileClientStartLog> GetList()
        {
            var data = clientLogRepository.GetList();
            return data;
        }

    }
}
